'use strict'

import fly from '@/utils/fly'
import { getOpenid } from '@/utils/login'

let getLocation = function () {
  return new Promise((resolve, reject) => {
    wx.getLocation({
      success: function (res) {
        console.log('getLocation', res)
        resolve(res)
      },
      fail: function (e) {
        let _res = {
          latitude: -1,
          longitude: -1
        }
        resolve(_res)
      }
    })
  })
}

export async function reportData (options) {
  // return []
  let openid = await getOpenid()
  let location = await getLocation()
  let from = ''
  if (options.from) {
    from = '' + options.from
  }
  let res = await fly.post(`InfoReport/infoCollect?wx_openid=${openid}&funcx=${encodeURIComponent(options.funcx)}&keyx=${encodeURIComponent(options.keyx)}&longitude=${location.longitude}&latitude=${location.latitude}&from=${from}`)
  if (res && res.code === 200 && res.data) {
    return res.data
  } else {
    return []
  }
}
